package com.teaching.teachingsupport.common.api;

import com.teaching.teachingsupport.common.enums.ResultStatusEnum;
import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String message;
    private T data;

    private Result() {
    }

    private Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(ResultStatusEnum.SUCCESS.getCode(), ResultStatusEnum.SUCCESS.getMessage(), null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultStatusEnum.SUCCESS.getCode(), ResultStatusEnum.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(ResultStatusEnum.SUCCESS.getCode(), message, data);
    }

    public static <T> Result<T> failed() {
        return new Result<>(ResultStatusEnum.FAIL.getCode(), ResultStatusEnum.FAIL.getMessage(), null);
    }

    public static <T> Result<T> failed(String message) {
        return new Result<>(ResultStatusEnum.FAIL.getCode(), message, null);
    }

    public static <T> Result<T> failed(ResultStatusEnum errorResult) {
        return new Result<>(errorResult.getCode(), errorResult.getMessage(), null);
    }

    public static <T> Result<T> failed(ResultStatusEnum errorResult, String message) {
        return new Result<>(errorResult.getCode(), message, null);
    }
} 